home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 47 / Amiga Format AFCD47 (Issue 131, Xmas 1999).iso / -serious- / emulation / electrostatic / hidden / mos6507.i < prev    next >
Text File  |  1999-10-04  |  18KB  |  1,586 lines

  1. ; File: MOS6507.i
  2. ; Author: Neil Cafferkey
  3. ; ======================
  4. ; Translations for MOS 6507 microprocessor instructions.
  5. ;
  6. ; $VER: MOS6507.i 1.1 (17.6.99)
  7. ;
  8.  
  9.     ifnd    mos6507_i
  10. mos6507_i    set    1
  11.  
  12.  
  13. ; 68020 Condition Codes
  14. ; =====================
  15.  
  16. extend        equ    4
  17. negative    equ    3
  18. zero        equ    2
  19. overflow    equ    1
  20. carry        equ    0
  21.  
  22.  
  23.  
  24.  
  25. INTERRUPT_VECTOR    equ    $fffe
  26. STACK_PAGE        equ    $0    ; should be $100 for other systems
  27.  
  28.  
  29.  
  30.     machine    68020
  31.  
  32.     opt    0
  33.  
  34.  
  35. ADDR_MASK    equ    $1fff    ; Makes a 13-bit address
  36.  
  37.  
  38. ; Register definitions
  39. ; ====================
  40.  
  41. A    equr    d2
  42. X    equr    d3
  43. Y    equr    d4
  44. P    equr    d5
  45. D_FLAG    equr    d6
  46. S    equr    d7
  47.  
  48. DATA    equr    a2
  49. CLOCK    equr    a3    ; this is an address register so that adding to it
  50.             ;    won't affect condition codes
  51. ENV    equr    a4
  52.  
  53.  
  54. ; Macro to save status flags
  55. ; ==========================
  56.  
  57.     macro    SAVE_P
  58.     move.w    ccr,d0
  59.     and.b    #\1,d0        ; clear irrelevant bits in ccr
  60.     and.b    #~\1,P        ; clear relevant bits in P
  61.     or.b    d0,P        ; move relevant bits to P
  62.     endm
  63.  
  64.  
  65. ; Macro to restore status flags
  66. ; =============================
  67.  
  68.     macro    LOAD_P
  69.     move.w    P,ccr
  70.     endm
  71.  
  72.  
  73. ; Macro to restore status flags within a macro
  74. ; ============================================
  75.  
  76.     macro    LOAD_P_INTERNAL
  77.     move.w    P,ccr
  78.     endm
  79.  
  80.  
  81. ; Macro: ABI_CLK
  82. ; ==============
  83. ; Adds one extra to the clock cycle counter if a page boundary is crossed.
  84.  
  85.     macro    ABI_CLK
  86.  
  87.     ifgt    128-\1
  88.     moveq    #\1,d0
  89.     else
  90.     move.l    #\1,d0
  91.     endc
  92.  
  93.     add.b    \2,d0
  94.  
  95.     moveq    #0,d0
  96.     roxl.b    #1,d0
  97.     addq.b    \3,d0
  98.     add.l    d0,CLOCK
  99.  
  100.     endm
  101.  
  102.  
  103. ; Macro: IIY_CLK
  104. ; ==============
  105. ; Adds one extra to the clock cycle counter if a page boundary is crossed.
  106.  
  107.     macro    IIY_CLK
  108.  
  109.     ifgt    128-\1
  110.     moveq    #\1,d0
  111.     else
  112.     move.l    #\1,d0
  113.     endc
  114.  
  115.     add.b    Y,d0
  116.  
  117.     moveq    #0,d0
  118.     roxl.b    #1,d0
  119.     addq.b    \2,d0
  120.     add.l    d0,CLOCK
  121.  
  122.     endm
  123.  
  124.  
  125. ; Zero Page Indexed
  126. ; =================
  127.  
  128.     macro    _ZPI
  129.     ifgt    128-\1
  130.     moveq    #\1,d1
  131.     else
  132.     move.l    #\1,d1
  133.     endc
  134.     add.b    \2,d1
  135.     endm
  136.  
  137.  
  138. ; Absolute Indexed
  139. ; ================
  140.  
  141.     macro    _ABI
  142.     ifgt    128-\1
  143.     moveq    #\1,d1
  144.     else
  145.     move.l    #\1,d1
  146.     endc
  147.     add.w    \2,d1
  148.     andi.w    #ADDR_MASK,d1
  149.     endm
  150.  
  151.  
  152. ; Indexed Indirect
  153. ; ================
  154.  
  155.     macro    _IIX
  156.     move.l    #\1,d1            ; Move offset to temp reg
  157.     add.b    X,d1            ; Add in index X
  158.     move.w    (DATA,d1),d1
  159.     rol.w    #8,d1            ; Adjust Endianness
  160.     andi.w    #ADDR_MASK,d1
  161.     endm
  162.  
  163.  
  164. ; Indirect Indexed
  165. ; ================
  166.  
  167.     macro    _IIY
  168.     move.w    (\1,DATA),d1
  169.     rol.w    #8,d1
  170.     add.w    Y,d1            ; Correctly handles word wrap-around
  171.     andi.w    #ADDR_MASK,d1
  172.     endm
  173.  
  174.  
  175. ; Translation of `adc'
  176. ; ====================
  177.  
  178. ; General translation
  179.  
  180.     macro    ADC_
  181.     move.b    P,d1
  182.     lsr.b    #1,d1
  183.     tst.b    D_FLAG
  184.     bne.s    \@1$        ; if in BCD mode
  185.     addx.b    d0,A
  186.     bra.s    \@2$
  187. \@1$:    move.b    A,d1
  188.     abcd.b    d0,A
  189.  
  190.     eor.b    A,d1
  191.     eor.b    A,d0
  192.     and.b    d1,d0
  193.  
  194.     move.w    ccr,d1
  195.     lsr.b    #7,d0
  196.     lsl.b    #4,d1
  197.     roxl.b    #1,d0
  198.  
  199.     tst.b    A
  200.     move.w    ccr,d1
  201.     or.b    d0,d1
  202.     move.w    d1,ccr
  203.  
  204. \@2$:
  205.     endm
  206.  
  207. ; Immediate
  208.  
  209.     macro    ADC_IMM
  210.     addq.l    #2,CLOCK
  211.     move.b    \1,d0
  212.     ADC_
  213.     endm
  214.  
  215. ; Zero Page
  216.  
  217.     macro    ADC_ZP
  218.     addq.l    #3,CLOCK
  219.     move.b    (\1,DATA),d0
  220.     ADC_
  221.     endm
  222.  
  223. ; Zero Page Indexed
  224.  
  225.     macro    ADC_ZPI
  226.     addq.l    #4,CLOCK
  227.     _ZPI    \1,\2
  228.     move.b    (DATA,d1),d0
  229.     ADC_
  230.     endm
  231.  
  232. ; Absolute
  233.  
  234.     macro    ADC_AB
  235.     move.b    (\1,DATA),d0
  236.     ADC_
  237.     addq.l    #4,CLOCK
  238.     endm
  239.  
  240. ; Absolute Indexed
  241.  
  242.     macro    ADC_ABI
  243.     ABI_CLK    \1,\2,#4
  244.     _ABI    \1,\2
  245.     move.b    (DATA,d1),d0
  246.     ADC_
  247.     endm
  248.  
  249. ; Indexed Indirect
  250.  
  251.     macro    ADC_IIX
  252.     addq.l    #6,CLOCK
  253.     _IIX    \1
  254.     move.b    (DATA,d1),d0
  255.     ADC_
  256.     endm
  257.  
  258. ; Indirect Indexed
  259.  
  260.     macro    ADC_IIY
  261.     IIY_CLK    \1,#5
  262.     _IIY    \1
  263.     move.b    (DATA,d1.w),d0
  264.     ADC_
  265.     endm
  266.  
  267.  
  268.  
  269. ; Translation of `and'
  270. ; ====================
  271.  
  272. ; Immediate
  273.  
  274.     macro    AND_IMM
  275.     addq.l    #2,CLOCK
  276.     andi.b    \1,A
  277.     endm
  278.  
  279. ; Zero Page
  280.  
  281.     macro    AND_ZP
  282.     addq.l    #3,CLOCK
  283.     and.b    (\1,DATA),A
  284.     endm
  285.  
  286. ; Zero Page Indexed
  287.  
  288.     macro    AND_ZPI
  289.     addq.l    #4,CLOCK
  290.     _ZPI    \1,\2
  291.     and.b    (DATA,d1),A
  292.     endm
  293.  
  294. ; Absolute
  295.  
  296.     macro    AND_AB
  297.     addq.l    #4,CLOCK
  298.     and.b    (\1,DATA),A
  299.     endm
  300.  
  301. ; Absolute Indexed
  302.  
  303.     macro    AND_ABI
  304.     ABI_CLK    \1,\2,#4
  305.     _ABI    \1,\2
  306.     and.b    (DATA,d1),A
  307.     endm
  308.  
  309. ; Indexed Indirect
  310.  
  311.     macro    AND_IIX
  312.     addq.l    #6,CLOCK
  313.     _IIX    \1
  314.     and.b    (DATA,d1),A
  315.     endm
  316.  
  317. ; Indirect Indexed
  318.  
  319.     macro    AND_IIY
  320.     IIY_CLK    \1,#5
  321.     _IIY    \1
  322.     and.b    (DATA,d1.w),A
  323.     endm
  324.  
  325.  
  326. ; Translation of `asl'
  327. ; ====================
  328.  
  329. ; General translation
  330.  
  331.     macro    ASL_
  332.     movem.w    (\1-1,DATA),d0
  333.     asl.b    #1,d0
  334.     movem.w    d0,(\1-1,DATA)
  335.     endm
  336.  
  337. ; Accumulator
  338.  
  339.     macro    ASL_ACC
  340.     addq.l    #2,CLOCK
  341.     asl.b    #1,A        ; All these could also be lsl.b
  342.     endm
  343.  
  344. ; Zero Page
  345.  
  346.     macro    ASL_ZP
  347.     addq.l    #5,CLOCK
  348.     ASL_    \1
  349.     endm
  350.  
  351. ; Zero Page Indexed
  352.  
  353.     macro    ASL_ZPI
  354.     addq.l    #6,CLOCK
  355.     _ZPI    \1,\2
  356.     movem.w    (-1,DATA,d1),d0
  357.     asl.b    #1,d0
  358.     movem.w    d0,(-1,DATA,d1)
  359.     endm
  360.  
  361. ; Absolute
  362.  
  363.     macro    ASL_AB
  364.     addq.l    #6,CLOCK
  365.     ASL_    \1
  366.     endm
  367.  
  368. ; Absolute Indexed
  369.  
  370.     macro    ASL_ABI
  371.     addq.l    #7,CLOCK
  372.     _ABI    \1,\2
  373.     move.w    (-1,DATA,d1),d0
  374.     asl.b    #1,d0
  375.     movem.w    d0,(-1,DATA,d1)
  376.     endm
  377.  
  378.  
  379. ; Translation of `bcc'
  380. ; ====================
  381.  
  382.     macro    BCC_
  383.     bcs.s    \@1$
  384.     addq.l    #3+\2,CLOCK
  385.     bra    \1
  386. \@1$:    addq.l    #2,CLOCK
  387.     endm
  388.  
  389.  
  390. ; Translation of `bcs'
  391. ; ====================
  392.  
  393.     macro    BCS_
  394.     bcc.s    \@1$
  395.     addq.l    #3+\2,CLOCK
  396.     bra    \1
  397. \@1$:    addq.l    #2,CLOCK
  398.     endm
  399.  
  400.  
  401. ; Translation of `beq'
  402. ; ====================
  403.  
  404.     macro    BEQ_
  405.     bne.s    \@1$
  406.     addq.l    #3+\2,CLOCK
  407.     bra    \1
  408. \@1$:    addq.l    #2,CLOCK
  409.     endm
  410.  
  411.  
  412. ; Translation of `bit'
  413. ; ====================
  414.  
  415. ; General translation
  416.  
  417.     macro    BIT_
  418.     moveq    #0,d1
  419.     move.b    (\1,DATA),d0
  420.     bpl.s    \@0$
  421.     bset.b    #negative,d1
  422. \@0$:    btst.b    #6,d0
  423.     beq.s    \@1$
  424.     bset.b    #overflow,d1
  425. \@1$:    and.b    A,d0
  426.     bne.s    \@2$
  427.     bset.b    #zero,d1
  428. \@2$:    move.w    d1,ccr
  429.  
  430.     endm
  431.  
  432. ; Zero Page
  433.  
  434.     macro    BIT_ZP
  435.     addq.l    #3,CLOCK
  436.     BIT_    \1
  437.     endm
  438.  
  439. ; Absolute
  440.  
  441.     macro    BIT_AB
  442.     addq.l    #4,CLOCK
  443.     BIT_    \1
  444.     endm
  445.  
  446.  
  447. ; Translation of `bmi'
  448. ; ====================
  449.  
  450.     macro    BMI_
  451.     bpl.s    \@1$
  452.     addq.l    #3+\2,CLOCK
  453.     bra    \1
  454. \@1$:    addq.l    #2,CLOCK
  455.     endm
  456.  
  457.  
  458. ; Translation of `bne'
  459. ; ====================
  460.  
  461.     macro    BNE_
  462.     beq.s    \@1$
  463.     addq.l    #3+\2,CLOCK
  464.     bra    \1
  465. \@1$:    addq.l    #2,CLOCK
  466.     endm
  467.  
  468.  
  469. ; Translation of `bpl'
  470. ; ====================
  471.  
  472.     macro    BPL_
  473.     bmi.s    \@1$
  474.     addq.l    #3+\2,CLOCK
  475.     bra    \1
  476. \@1$:    addq.l    #2,CLOCK
  477.     endm
  478.  
  479.  
  480. ; Translation of `brk'
  481. ; ====================
  482.  
  483.     macro    BRK_
  484.  
  485.     addq.l    #7,CLOCK
  486.  
  487.     move.l    P,-(sp)
  488.  
  489.     subq.b    #2,S
  490.     move.b    P,(STACK_PAGE,DATA,S)
  491.     subq.b    #1,S
  492.  
  493.     INTERRUPT
  494.  
  495.     endm
  496.  
  497.  
  498. ; Translation of `bvc'
  499. ; ====================
  500.  
  501.     macro    BVC_
  502.     bvs.s    \@1$
  503.     addq.l    #3+\2,CLOCK
  504.     bra    \1
  505. \@1$:    addq.l    #2,CLOCK
  506.     endm
  507.  
  508.  
  509. ; Translation of `bvs'
  510. ; ====================
  511.  
  512.     macro    BVS_
  513.     bvc.s    \@1$
  514.     addq.l    #3+\2,CLOCK
  515.     bra    \1
  516. \@1$:    addq.l    #2,CLOCK
  517.     endm
  518.  
  519.  
  520. ; Translation of `clc'
  521. ; ====================
  522.  
  523.     macro    CLC_
  524.     addq.l    #2,CLOCK
  525.     moveq    #0,d0        ; clear carry flag
  526.     endm
  527.  
  528.  
  529. ; Translation of `cld'
  530. ; ====================
  531.  
  532.     macro    CLD_
  533.     addq.l    #2,CLOCK
  534.     moveq    #0,D_FLAG
  535.     endm
  536.  
  537.  
  538. ; Translation of `cli' (not yet implemented)
  539. ; ====================
  540.  
  541.     macro    CLI_
  542.     addq.l    #2,CLOCK
  543.     endm
  544.  
  545.  
  546. ; Translation of `clv'
  547. ; ====================
  548.  
  549.     macro    CLV_
  550.     addq.l    #2,CLOCK
  551.     moveq    #0,d0        ; clear overflow flag
  552.     endm
  553.  
  554.  
  555. ; Translation of `cmp'
  556. ; ====================
  557.  
  558. ; Immediate
  559.  
  560.     macro    CMP_IMM
  561.     addq.l    #2,CLOCK
  562.     cmpi.b    \1,A
  563.     eori.b    #$01,ccr    ; flip carry flag
  564.     endm
  565.  
  566. ; Zero Page
  567.  
  568.     macro    CMP_ZP
  569.     addq.l    #3,CLOCK
  570.     cmp.b    (\1,DATA),A
  571.     eori.b    #$01,ccr    ; flip carry flag
  572.     endm
  573.  
  574. ; Zero Page Indexed
  575.  
  576.     macro    CMP_ZPI
  577.     _ZPI    \1,\2
  578.     cmp.b    (DATA,d1),A
  579.     addq.l    #4,CLOCK
  580.     eori.b    #$01,ccr    ; flip carry flag
  581.     endm
  582.  
  583. ; Absolute
  584.  
  585.     macro    CMP_AB
  586.     addq.l    #4,CLOCK
  587.     cmp.b    (\1,DATA),A
  588.     eori.b    #$01,ccr    ; flip carry flag
  589.     endm
  590.  
  591. ; Absolute Indexed
  592.  
  593.     macro    CMP_ABI
  594.     ABI_CLK    \1,\2,#4
  595.     _ABI    \1,\2
  596.     cmp.b    (DATA,d1),A
  597.     eori.b    #$01,ccr    ; flip carry flag
  598.     endm
  599.  
  600. ; Indexed Indirect
  601.  
  602.     macro    CMP_IIX
  603.     addq.l    #6,CLOCK
  604.     _IIX    \1
  605.     cmp.b    (DATA,d1),A
  606.     eori.b    #$01,ccr    ; flip carry flag
  607.     endm
  608.  
  609. ; Indirect Indexed
  610.  
  611.     macro    CMP_IIY
  612.     IIY_CLK    \1,#5
  613.     _IIY    \1
  614.     cmp.b    (DATA,d1.w),A
  615.     eori.b    #$01,ccr    ; flip carry flag
  616.     endm
  617.  
  618.  
  619. ; Translation of `cpx'
  620. ; ====================
  621.  
  622. ; Immediate
  623.  
  624.     macro    CPX_IMM
  625.     addq.l    #2,CLOCK
  626.     cmpi.b    \1,X
  627.     eori.b    #$01,ccr    ; flip carry flag
  628.     endm
  629.  
  630. ; Zero Page
  631.  
  632.     macro    CPX_ZP
  633.     addq.l    #3,CLOCK
  634.     cmp.b    (\1,DATA),X
  635.     eori.b    #$01,ccr    ; flip carry flag
  636.     endm
  637.  
  638. ; Absolute
  639.  
  640.     macro    CPX_AB
  641.     addq.l    #4,CLOCK
  642.     cmp.b    (\1,DATA),X
  643.     eori.b    #$01,ccr    ; flip carry flag
  644.     endm
  645.  
  646.  
  647. ; Translation of `cpy'
  648. ; ====================
  649.  
  650. ; Immediate
  651.  
  652.     macro    CPY_IMM
  653.     addq.l    #2,CLOCK
  654.     cmpi.b    \1,Y
  655.     eori.b    #$01,ccr    ; flip carry flag
  656.     endm
  657.  
  658. ; Zero Page
  659.  
  660.     macro    CPY_ZP
  661.     addq.l    #3,CLOCK
  662.     cmp.b    (\1,DATA),Y
  663.     eori.b    #$01,ccr    ; flip carry flag
  664.     endm
  665.  
  666. ; Absolute
  667.  
  668.     macro    CPY_AB
  669.     addq.l    #4,CLOCK
  670.     cmp.b    (\1,DATA),Y
  671.     eori.b    #$01,ccr    ; flip carry flag
  672.     endm
  673.  
  674.  
  675. ; Translation of `dec'
  676. ; ====================
  677.  
  678. ; Zero Page
  679.  
  680.     macro    DEC_ZP
  681.     addq.l    #5,CLOCK
  682.     subq.b    #1,(\1,DATA)
  683.     endm
  684.  
  685. ; Zero Page Indexed
  686.  
  687.     macro    DEC_ZPI
  688.     addq.l    #6,CLOCK
  689.     _ZPI    \1,\2
  690.     subq.b    #1,(DATA,d1)
  691.     endm
  692.  
  693. ; Absolute
  694.  
  695.     macro    DEC_AB
  696.     addq.l    #6,CLOCK
  697.     subq.b    #1,(\1,DATA)
  698.     endm
  699.  
  700. ; Absolute Indexed
  701.  
  702.     macro    DEC_ABI
  703.     addq.l    #7,CLOCK
  704.     _ABI    \1,\2
  705.     subq.b    #1,(DATA,d1.w)
  706.     endm
  707.  
  708. ; Translation of `dex'
  709. ; ====================
  710.  
  711.     macro    DEX_
  712.     addq.l    #2,CLOCK
  713.     subq.b    #1,X
  714.     endm
  715.  
  716.  
  717. ; Translation of `dey'
  718. ; ====================
  719.  
  720.     macro    DEY_
  721.     addq.l    #2,CLOCK
  722.     subq.b    #1,Y
  723.     endm
  724.  
  725. ; Translation of `eor'
  726. ; ====================
  727.  
  728. ; Immediate
  729.  
  730.     macro    EOR_IMM
  731.     addq.l    #2,CLOCK
  732.     eori.b    \1,A
  733.     endm
  734.  
  735. ; Zero Page
  736.  
  737.     macro    EOR_ZP
  738.     addq.l    #3,CLOCK
  739.     move.b    (\1,DATA),d0
  740.     eor.b    d0,A
  741.     endm
  742.  
  743. ; Zero Page Indexed
  744.  
  745.     macro    EOR_ZPI
  746.     addq.l    #4,CLOCK
  747.     _ZPI    \1,\2
  748.     move.b    (DATA,d1),d0
  749.     eor.b    d0,A
  750.     endm
  751.  
  752. ; Absolute
  753.  
  754.     macro    EOR_AB
  755.     addq.l    #4,CLOCK
  756.     move.b    (\1,DATA),d0
  757.     eor.b    d0,A
  758.     endm
  759.  
  760. ; Absolute Indexed
  761.  
  762.     macro    EOR_ABI
  763.     ABI_CLK    \1,\2,#4
  764.     _ABI    \1,\2
  765.     move.b    (DATA,d1),d0
  766.     eor.b    d0,A
  767.     endm
  768.  
  769. ; Indexed Indirect
  770.  
  771.     macro    EOR_IIX
  772.     addq.l    #6,CLOCK
  773.     _IIX    \1
  774.     move.b    (DATA,d1),d0
  775.     eor.b    d0,A
  776.     endm
  777.  
  778. ; Indirect Indexed
  779.  
  780.     macro    EOR_IIY
  781.     IIY_CLK    \1,#5
  782.     _IIY    \1
  783.     move.b    (DATA,d1.w),d0
  784.     eor.b    d0,A
  785.     endm
  786.  
  787.  
  788. ; Translation of `inc'
  789. ; ====================
  790.  
  791. ; Zero Page
  792.  
  793.     macro    INC_ZP
  794.     addq.l    #5,CLOCK
  795.     addq.b    #1,(\1,DATA)
  796.     endm
  797.  
  798. ; Zero Page Indexed
  799.  
  800.     macro    INC_ZPI
  801.     addq.l    #6,CLOCK
  802.     _ZPI    \1,\2
  803.     addq.b    #1,(DATA,d1)
  804.     endm
  805.  
  806. ; Absolute
  807.  
  808.     macro    INC_AB
  809.     addq.l    #6,CLOCK
  810.     addq.b    #1,(\1,DATA)
  811.     endm
  812.  
  813. ; Absolute Indexed
  814.  
  815.     macro    INC_ABI
  816.     addq.l    #7,CLOCK
  817.     _ABI    \1,\2
  818.     addq.b    #1,(DATA,d1)
  819.     endm
  820.  
  821.  
  822. ; Translation of `inx'
  823. ; ====================
  824.  
  825.     macro    INX_
  826.     addq.l    #2,CLOCK
  827.     addq.b    #1,X
  828.     endm
  829.  
  830.  
  831. ; Translation of `iny'
  832. ; ====================
  833.  
  834.     macro    INY_
  835.     addq.l    #2,CLOCK
  836.     addq.b    #1,Y
  837.     endm
  838.  
  839.  
  840. ; Translation of `jmp'
  841. ; ====================
  842.  
  843. ; Absolute
  844.  
  845.     macro    JMP_AB
  846.     addq.l    #3,CLOCK
  847.     bra    \1
  848.     endm
  849.  
  850. ; Indirect (not yet implemented)
  851.  
  852.     macro    JMP_MI
  853.     addq.l    #5,CLOCK
  854.     bra    \1    ; this is wrong
  855.     endm
  856.  
  857.  
  858. ; Translation of `jsr'
  859. ; ====================
  860.  
  861.     macro    JSR_
  862.     addq.l    #6,CLOCK
  863.     subq.b    #2,S
  864.     bsr    \1
  865.     endm
  866.  
  867.  
  868. ; Translation of `lda'
  869. ; ====================
  870.  
  871. ; Immediate
  872.  
  873.     macro    LDA_IMM
  874.     addq.l    #2,CLOCK
  875.     move.b    \1,A
  876.     endm
  877.  
  878. ; Zero Page
  879.  
  880.     macro    LDA_ZP
  881.     move.b    (\1,DATA),A
  882.     addq.l    #3,CLOCK
  883.     endm
  884.  
  885. ; Zero Page Indexed
  886.  
  887.     macro    LDA_ZPI
  888.     _ZPI    \1,\2
  889.     move.b    (DATA,d1),A
  890.     addq.l    #4,CLOCK
  891.     endm
  892.  
  893. ; Absolute
  894.  
  895.     macro    LDA_AB
  896.     move.b    (\1,DATA),A
  897.     addq.l    #4,CLOCK
  898.     endm
  899.  
  900. ; Absolute Indexed
  901.  
  902.     macro    LDA_ABI
  903.     ABI_CLK    \1,\2,#4
  904.     _ABI    \1,\2
  905.     move.b    (DATA,d1),A
  906.     endm
  907.  
  908. ; Indexed Indirect
  909.  
  910.     macro    LDA_IIX
  911.     addq.l    #6,CLOCK
  912.     _IIX    \1
  913.     move.b    (DATA,d1),A
  914.     endm
  915.  
  916. ; Indirect Indexed
  917.  
  918.     macro    LDA_IIY
  919.     IIY_CLK    \1,#5
  920.     _IIY    \1
  921.     move.b    (DATA,d1.w),A
  922.     endm
  923.  
  924.  
  925. ; Translation of `ldx'
  926. ; ====================
  927.  
  928. ; Immediate
  929.  
  930.     macro    LDX_IMM
  931.     move.b    \1,X
  932.     addq.l    #2,CLOCK
  933.     endm
  934.  
  935. ; Zero Page
  936.  
  937.     macro    LDX_ZP
  938.     move.b    (\1,DATA),X
  939.     addq.l    #3,CLOCK
  940.     endm
  941.  
  942. ; Zero Page Indexed
  943.  
  944.     macro    LDX_ZPI
  945.     _ZPI    \1,\2
  946.     move.b    (DATA,d1),X
  947.     addq.l    #4,CLOCK
  948.     endm
  949.  
  950. ; Absolute
  951.  
  952.     macro    LDX_AB
  953.     move.b    (\1,DATA),X
  954.     addq.l    #4,CLOCK
  955.     endm
  956.  
  957. ; Absolute Indexed
  958.  
  959.     macro    LDX_ABI
  960.     ABI_CLK    \1,\2,#4
  961.     _ABI    \1,\2
  962.     move.b    (DATA,d1),X
  963.     endm
  964.  
  965. ; Translation of `ldy'
  966. ; ====================
  967.  
  968. ; Immediate
  969.  
  970.     macro    LDY_IMM
  971.     move.b    \1,Y
  972.     addq.l    #2,CLOCK
  973.     endm
  974.  
  975. ; Zero Page
  976.  
  977.     macro    LDY_ZP
  978.     move.b    (\1,DATA),Y
  979.     addq.l    #3,CLOCK
  980.     endm
  981.  
  982. ; Zero Page Indexed
  983.  
  984.     macro    LDY_ZPI
  985.     _ZPI    \1,\2
  986.     move.b    (DATA,d1),Y
  987.     addq.l    #4,CLOCK
  988.     endm
  989.  
  990. ; Absolute
  991.  
  992.     macro    LDY_AB
  993.     move.b    (\1,DATA),Y
  994.     addq.l    #4,CLOCK
  995.     endm
  996.  
  997. ; Absolute Indexed
  998.  
  999.     macro    LDY_ABI
  1000.     ABI_CLK    \1,\2,#4
  1001.     _ABI    \1,\2
  1002.     move.b    (DATA,d1),Y
  1003.     endm
  1004.  
  1005.  
  1006. ; Translation of `lsr'
  1007. ; ====================
  1008.  
  1009. ; General translation
  1010.  
  1011.     macro    LSR_
  1012.     movem.w    (\1-1,DATA),d0
  1013.     lsr.b    #1,d0
  1014.     movem.w    d0,(\1-1,DATA)
  1015.     endm
  1016.  
  1017. ; Accumulator
  1018.  
  1019.     macro    LSR_ACC
  1020.     addq.l    #2,CLOCK
  1021.     lsr.b    #1,A
  1022.     endm
  1023.  
  1024. ; Zero Page
  1025.  
  1026.     macro    LSR_ZP
  1027.     addq.l    #5,CLOCK
  1028.     LSR_    \1
  1029.     endm
  1030.  
  1031. ; Zero Page Indexed
  1032.  
  1033.     macro    LSR_ZPI
  1034.     addq.l    #6,CLOCK
  1035.     _ZPI    \1,\2
  1036.     movem.w    (-1,DATA,d1),d0
  1037.     lsr.b    #1,d0
  1038.     movem.w    d0,(-1,DATA,d1)
  1039.     endm
  1040.  
  1041. ; Absolute
  1042.  
  1043.     macro    LSR_AB
  1044.     addq.l    #6,CLOCK
  1045.     LSR_    \1
  1046.     endm
  1047.  
  1048. ; Absolute Indexed
  1049.  
  1050.     macro    LSR_ABI
  1051.     addq.l    #7,CLOCK
  1052.     _ABI    \1,\2
  1053.     move.w    (-1,DATA,d1),d0
  1054.     lsr.b    #1,d0
  1055.     movem.w    d0,(-1,DATA,d1)
  1056.     endm
  1057.  
  1058.  
  1059. ; Translation of `nop'
  1060. ; ====================
  1061.  
  1062.     macro    NOP_
  1063.     addq.l    #2,CLOCK
  1064.     endm
  1065.  
  1066.  
  1067. ; Translation of `ora'
  1068. ; ====================
  1069.  
  1070. ; Immediate
  1071.  
  1072.     macro    ORA_IMM
  1073.     ori.b    \1,A
  1074.     addq.l    #2,CLOCK
  1075.     endm
  1076.  
  1077. ; Zero Page
  1078.  
  1079.     macro    ORA_ZP
  1080.     or.b    (\1,DATA),A
  1081.     addq.l    #3,CLOCK
  1082.     endm
  1083.  
  1084. ; Zero Page Indexed
  1085.  
  1086.     macro    ORA_ZPI
  1087.     _ZPI    \1,\2
  1088.     or.b    (DATA,d1),A
  1089.     addq.l    #4,CLOCK
  1090.     endm
  1091.  
  1092. ; Absolute
  1093.  
  1094.     macro    ORA_AB
  1095.     or.b    (\1,DATA),A
  1096.     addq.l    #4,CLOCK
  1097.     endm
  1098.  
  1099. ; Absolute Indexed
  1100.  
  1101.     macro    ORA_ABI
  1102.     ABI_CLK    \1,\2,#4
  1103.     _ABI    \1,\2
  1104.     or.b    (DATA,d1),A
  1105.     endm
  1106.  
  1107. ; Indexed Indirect
  1108.  
  1109.     macro    ORA_IIX
  1110.     addq.l    #6,CLOCK
  1111.     _IIX    \1
  1112.     or.b    (DATA,d1),A
  1113.     endm
  1114.  
  1115. ; Indirect Indexed
  1116.  
  1117.     macro    ORA_IIY
  1118.     IIY_CLK    \1,#5
  1119.     _IIY    \1
  1120.     or.b    (DATA,d1.w),A
  1121.     endm
  1122.  
  1123.  
  1124. ; Translation of `pha'
  1125. ; ====================
  1126.  
  1127.     macro    PHA_
  1128.     addq.l    #3,CLOCK
  1129.     move.l    A,-(sp)
  1130.     move.b    A,(STACK_PAGE,DATA,S)
  1131.     subq.b    #1,S
  1132.     endm
  1133.  
  1134.  
  1135. ; Translation of `php'
  1136. ; ====================
  1137.  
  1138.     macro    PHP_
  1139.     move.l    P,-(sp)
  1140.     move.b    P,(STACK_PAGE,DATA,S)
  1141.     subq.b    #1,S
  1142.     addq.l    #3,CLOCK
  1143.     endm
  1144.  
  1145.  
  1146. ; Translation of `pla'
  1147. ; ====================
  1148.  
  1149.     macro    PLA_
  1150.     move.l    (sp)+,A        ; discarded
  1151.     addq.b    #1,S
  1152.     move.b    (STACK_PAGE,DATA,S),A
  1153.     addq.l    #4,CLOCK
  1154.     endm
  1155.  
  1156.  
  1157. ; Translation of `plp'
  1158. ; ====================
  1159.  
  1160.     macro    PLP_
  1161.     addq.l    #4,CLOCK
  1162.     move.l    (sp)+,P        ; discarded
  1163.     addq.b    #1,S
  1164.     move.w    (STACK_PAGE-1,DATA,S),ccr
  1165.     endm
  1166.  
  1167.  
  1168. ; Translation of `rol'
  1169. ; ====================
  1170.  
  1171. ; General translation
  1172.  
  1173.     macro    ROL_
  1174.     move.w    (\1-1,DATA),d0
  1175.     move.b    P,d1
  1176.     lsr.b    #1,d1
  1177.     roxl.b    #1,d0
  1178.     movem.w    d0,(\1-1,DATA)
  1179.     endm
  1180.  
  1181. ; Accumulator
  1182.  
  1183.     macro    ROL_ACC
  1184.     addq.l    #2,CLOCK
  1185.     move.b    P,d1
  1186.     lsr.b    #1,d1
  1187.     roxl.b    #1,A
  1188.     endm
  1189.  
  1190. ; Zero Page
  1191.  
  1192.     macro    ROL_ZP
  1193.     addq.l    #5,CLOCK
  1194.     ROL_    \1
  1195.     endm
  1196.  
  1197. ; Zero Page Indexed
  1198.  
  1199.     macro    ROL_ZPI
  1200.     addq.l    #6,CLOCK
  1201.     _ZPI    \1,\2
  1202.     move.b    P,d0
  1203.     lsr.b    #1,d0
  1204.     movem.w    (-1,DATA,d1),d0
  1205.     roxl.b    #1,d0
  1206.     movem.w    d0,(-1,DATA,d1)
  1207.     endm
  1208.  
  1209. ; Absolute
  1210.  
  1211.     macro    ROL_AB
  1212.     addq.l    #6,CLOCK
  1213.     ROL_    \1
  1214.     endm
  1215.  
  1216. ; Absolute Indexed
  1217.  
  1218.     macro    ROL_ABI
  1219.     addq.l    #6,CLOCK
  1220.     _ABI    \1,\2
  1221.     move.b    P,d0
  1222.     lsb.b    #1,d0
  1223.     movem.w    (-1,DATA,d1.w),d0
  1224.     roxl.b    #1,d0
  1225.     movem.w    d0,(-1,DATA,d1.w)
  1226.     endm
  1227.  
  1228.  
  1229. ; Translation of `ror'
  1230. ; ====================
  1231.  
  1232. ; General translation
  1233.  
  1234.     macro    ROR_
  1235.     move.w    (\1-1,DATA),d0
  1236.     move.b    P,d1
  1237.     lsr.b    #1,d1
  1238.     roxr.b    #1,d0
  1239.     movem.w    d0,(\1-1,DATA)
  1240.     endm
  1241.  
  1242. ; Accumulator
  1243.  
  1244.     macro    ROR_ACC
  1245.     addq.l    #2,CLOCK
  1246.     move.b    P,d1
  1247.     lsr.b    #1,d1
  1248.     roxr.b    #1,A
  1249.     endm
  1250.  
  1251. ; Zero Page
  1252.  
  1253.     macro    ROR_ZP
  1254.     addq.l    #5,CLOCK
  1255.     ROR_    \1
  1256.     endm
  1257.  
  1258. ; Zero Page Indexed
  1259.  
  1260.     macro    ROR_ZPI
  1261.     addq.l    #6,CLOCK
  1262.     _ZPI    \1,\2
  1263.     move.b    P,d0
  1264.     lsr.b    #1,d0
  1265.     movem.w    (-1,DATA,d1),d0
  1266.     roxr.b    #1,d0
  1267.     movem.w    d0,(-1,DATA,d1)
  1268.     endm
  1269.  
  1270. ; Absolute
  1271.  
  1272.     macro    ROR_AB
  1273.     addq.l    #6,CLOCK
  1274.     ROR_    \1
  1275.     endm
  1276.  
  1277. ; Absolute Indexed
  1278.  
  1279.     macro    ROR_ABI
  1280.     addq.l    #6,CLOCK
  1281.     _ABI    \1,\2
  1282.     move.b    P,d0
  1283.     lsb.b    #1,d0
  1284.     movem.w    (-1,DATA,d1.w),d0
  1285.     roxr.b    #1,d0
  1286.     movem.w    d0,(-1,DATA,d1.w)
  1287.     endm
  1288.  
  1289.  
  1290. ; Translation of `rti'
  1291. ; ====================
  1292.  
  1293.     macro    RTI_
  1294.  
  1295.     addq.l    #6,CLOCK
  1296.  
  1297.     move.l    (sp)+,a0
  1298.  
  1299.     move.l    (sp)+,P        ; discarded
  1300.     addq.b    #1,S
  1301.     move.b    (STACK_PAGE-1,DATA,S),P
  1302.  
  1303.     addq.b    #2,S
  1304.  
  1305.     move.w    P,ccr
  1306.  
  1307.     jmp    (a0)
  1308.  
  1309.     endm
  1310.  
  1311.  
  1312. ; Translation of `rts'
  1313. ; ====================
  1314.  
  1315.     macro    RTS_
  1316.     addq.l    #6,CLOCK
  1317.     addq.b    #2,S
  1318.     rts
  1319.     endm
  1320.  
  1321.  
  1322. ; Translation of `sbc'
  1323. ; ====================
  1324.  
  1325. ; General translation
  1326.  
  1327.     macro    SBC_
  1328.     move.b    P,d1
  1329.     eori.b    #$01,d1
  1330.     lsr.b    #1,d1
  1331.     tst.b    D_FLAG
  1332.     bne.s    \@1$        ; if in BCD mode
  1333.     subx.b    d0,A
  1334.     bra.s    \@2$
  1335. \@1$:    ori.b    #$04,ccr    ; set zero flag
  1336.     sbcd.b    d0,A
  1337. \@2$:    eori.b    #$1,ccr        ; flip carry bit
  1338.     endm
  1339.  
  1340. ; Immediate
  1341.  
  1342.     macro    SBC_IMM
  1343.     addq.l    #2,CLOCK
  1344.     move.b    \1,d0
  1345.     SBC_
  1346.     endm
  1347.  
  1348. ; Zero Page
  1349.  
  1350.     macro    SBC_ZP
  1351.     move.b    (\1,DATA),d0
  1352.     SBC_    \1
  1353.     addq.l    #3,CLOCK
  1354.     endm
  1355.  
  1356. ; Zero Page Indexed
  1357.  
  1358.     macro    SBC_ZPI
  1359.     _ZPI    \1,\2
  1360.     move.b    (DATA,d1),d0
  1361.     SBC_
  1362.     addq.l    #4,CLOCK
  1363.     endm
  1364.  
  1365. ; Absolute
  1366.  
  1367.     macro    SBC_AB
  1368.     move.b    (\1,DATA),d0
  1369.     SBC_
  1370.     addq.l    #4,CLOCK
  1371.     endm
  1372.  
  1373. ; Absolute Indexed
  1374.  
  1375.     macro    SBC_ABI
  1376.     ABI_CLK    \1,\2,#4
  1377.     _ABI    \1,\2
  1378.     move.b    (DATA,d1),d0
  1379.     SBC_
  1380.     endm
  1381.  
  1382. ; Indexed Indirect
  1383.  
  1384.     macro    SBC_IIX
  1385.     _IIX    \1
  1386.     move.b    (DATA,d1),d0
  1387.     SBC_
  1388.     addq.l    #6,CLOCK
  1389.     endm
  1390.  
  1391. ; Indirect Indexed
  1392.  
  1393.     macro    SBC_IIY
  1394.     IIY_CLK    \1,#5
  1395.     _IIY    \1
  1396.     move.b    (DATA,d1.w),d0
  1397.     SBC_
  1398.     endm
  1399.  
  1400.  
  1401.  
  1402. ; Translation of `sec'
  1403. ; ====================
  1404.  
  1405.     macro    SEC_
  1406.     addq.l    #2,CLOCK
  1407.     move.b    #$01,ccr    ; set carry bit
  1408.     endm
  1409.  
  1410.  
  1411. ; Translation of `sed'
  1412. ; ====================
  1413.  
  1414.     macro    SED_
  1415.     addq.l    #2,CLOCK
  1416.     moveq    #1,D_FLAG
  1417.     endm
  1418.  
  1419.  
  1420. ; Translation of `sei'
  1421. ; ====================
  1422.  
  1423.     macro    SEI_
  1424.     addq.l    #2,CLOCK
  1425.     endm
  1426.  
  1427.  
  1428. ; Translation of `sta'
  1429. ; ====================
  1430.  
  1431. ; Zero Page
  1432.  
  1433.     macro    STA_ZP
  1434.     addq.l    #3,CLOCK
  1435.     move.b    A,(\1,DATA)
  1436.     endm
  1437.  
  1438. ; Zero Page Indexed
  1439.  
  1440.     macro    STA_ZPI
  1441.     _ZPI    \1,\2
  1442.     move.b    A,(DATA,d1)
  1443.     addq.l    #4,CLOCK
  1444.     endm
  1445.  
  1446. ; Absolute
  1447.  
  1448.     macro    STA_AB
  1449.     move.b    A,(\1,DATA)
  1450.     addq.l    #4,CLOCK
  1451.     endm
  1452.  
  1453. ; Absolute Indexed
  1454.  
  1455.     macro    STA_ABI
  1456.     addq.l    #5,CLOCK
  1457.     _ABI    \1,\2
  1458.     move.b    A,(DATA,d1)
  1459.     endm
  1460.  
  1461. ; Indexed Indirect
  1462.  
  1463.     macro    STA_IIX
  1464.     _IIX    \1
  1465.     move.b    A,(DATA,d1)
  1466.     addq.l    #6,CLOCK
  1467.     endm
  1468.  
  1469. ; Indirect Indexed
  1470.  
  1471.     macro    STA_IIY
  1472.     _IIY    \1
  1473.     move.b    A,(DATA,d1.w)
  1474.     addq.l    #6,CLOCK
  1475.     endm
  1476.  
  1477.  
  1478. ; Translation of `stx'
  1479. ; ====================
  1480.  
  1481. ; Zero Page
  1482.  
  1483.     macro    STX_ZP
  1484.     move.b    X,(\1,DATA)
  1485.     addq.l    #3,CLOCK
  1486.     endm
  1487.  
  1488. ; Zero Page Indexed
  1489.  
  1490.     macro    STX_ZPI
  1491.     _ZPI    \1,\2
  1492.     move.b    X,(DATA,d1)
  1493.     addq.l    #4,CLOCK
  1494.     endm
  1495.  
  1496. ; Absolute
  1497.  
  1498.     macro    STX_AB
  1499.     move.b    X,(\1,DATA)
  1500.     addq.l    #4,CLOCK
  1501.     endm
  1502.  
  1503.  
  1504. ; Translation of `sty'
  1505. ; ====================
  1506.  
  1507. ; Zero Page
  1508.  
  1509.     macro    STY_ZP
  1510.     move.b    Y,(\1,DATA)
  1511.     addq.l    #3,CLOCK
  1512.     endm
  1513.  
  1514. ; Zero Page Indexed
  1515.  
  1516.     macro    STY_ZPI
  1517.     _ZPI    \1,\2
  1518.     move.b    Y,(DATA,d1)
  1519.     addq.l    #4,CLOCK
  1520.     endm
  1521.  
  1522. ; Absolute
  1523.  
  1524.     macro    STY_AB
  1525.     move.b    Y,(\1,DATA)
  1526.     addq.l    #4,CLOCK
  1527.     endm
  1528.  
  1529.  
  1530. ; Translation of `tax'
  1531. ; ====================
  1532.  
  1533.     macro    TAX_
  1534.     move.b    A,X
  1535.     addq.l    #2,CLOCK
  1536.     endm
  1537.  
  1538.  
  1539. ; Translation of `tay'
  1540. ; ====================
  1541.  
  1542.     macro    TAY_
  1543.     move.b    A,Y
  1544.     addq.l    #2,CLOCK
  1545.     endm
  1546.  
  1547.  
  1548. ; Translation of `tsx'
  1549. ; ====================
  1550.  
  1551.     macro    TSX_
  1552.     move.b    S,X
  1553.     addq.l    #2,CLOCK
  1554.     endm
  1555.  
  1556.  
  1557. ; Translation of `txa'
  1558. ; ====================
  1559.  
  1560.     macro    TXA_
  1561.     move.b    X,A
  1562.     addq.l    #2,CLOCK
  1563.     endm
  1564.  
  1565.  
  1566. ; Translation of `txs'
  1567. ; ====================
  1568.  
  1569.     macro    TXS_
  1570.     addq.l    #2,CLOCK
  1571.     move.b    X,S
  1572.     endm
  1573.  
  1574.  
  1575. ; Translation of `tya'
  1576. ; ====================
  1577.  
  1578.     macro    TYA_
  1579.     move.b    Y,A
  1580.     addq.l    #2,CLOCK
  1581.     endm
  1582.  
  1583.  
  1584.     endc
  1585.  
  1586.